/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.web.search;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import org.hutech09.jsale.bsn.IProductManager;
import org.hutech09.jsale.bsn.exception.ItemNotFoundException;
import org.hutech09.jsale.entity.Product;
import org.hutech09.jsale.web.customer.cusController;
import org.hutech09.jsale.web.product.productController;
import org.hutech09.jsale.web.product.productDetail;

/**
 *
 * @author abc
 */
@ManagedBean
@SessionScoped
public class SearchController {

    @EJB
    private IProductManager iProductManager;
     @ManagedProperty(value = "#{productController}")
     private productController productController;

    public productController getProductController() {
        return productController;
    }

    public void setProductController(productController productController) {
        this.productController = productController;
    }
     
//    private cusController cusController;
//    @ManagedProperty(value = "#{productController")
//    private productController pcontroller;
    private List<productDetail> listPdetailBySearch;
    private String btnName;

   

    
    private String query;

  
    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }
    
    public String getBtnName() {
        return btnName;
    }

    public void setBtnName(String btnName) {
        this.btnName = btnName;
    }

    public void changName(String name) {
        if (name.equals("product")) {
            setBtnName("Product");
        } else {
            if (name.equals("catelogy")) {
                setBtnName("Catelogy");
            } else {
               setBtnName("ProductType");
            }
        }
    }
    public String search() throws ItemNotFoundException
    {
        listPdetailBySearch = new ArrayList<productDetail>();
        List<Product> listproduct = new ArrayList<Product>();
        if(this.btnName.equals("Product"))
        {
            listproduct = iProductManager.findProductByName(query);
           getProductController().getlistbysearch(listproduct);
        }
        return "home";
    }

    public SearchController() {
    }
}
